package io.bdmc.modules.bss.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.R;
import io.bdmc.modules.bss.entity.DeviceRouteConfig;
import io.bdmc.modules.bss.service.IDeviceRouteConfigService;
import io.bdmc.modules.sys.controller.AbstractController;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 路由参数配置 前端控制器
 * </p>
 *
 * @author 黄露
 * @since 2021-06-07
 */

// "路由参数配置", description = "路由参数配置")
@RestController
@RequestMapping("/bss/route/config")
public class DeviceRouteConfigController extends AbstractController {

    @Autowired
    IDeviceRouteConfigService routeConfigService;

    @GetMapping("/list")
    // "查询路由参数配置", notes = "查询路由参数配置")
    // @RequiresPermissions("bss:deviceRouteConfig:list")
    public R list(Integer routeId) {
        final List<DeviceRouteConfig> routeConfigs = routeConfigService
                .list(new QueryWrapper<DeviceRouteConfig>().eq("route_id", routeId));
        return R.ok().putData(routeConfigs);
    }

    @SysLogger("新增路由参数配置")
    @PostMapping("/add")
    // "新增路由参数配置", notes = "新增路由参数配置")
    // @RequiresPermissions("bss:deviceRouteConfig:add")
    public R add(@RequestBody DeviceRouteConfig devicerouteconfig) {
        Boolean b = devicerouteconfig.insert();
        return R.trueOrFalse(b);
    }

    @SysLogger("修改路由参数配置")
    @PostMapping("/update")
    // "修改路由参数配置", notes = "修改路由参数配置")
    // @RequiresPermissions("bss:deviceRouteConfig:update")
    public R update(@RequestBody DeviceRouteConfig devicerouteconfig) {
        Boolean b = devicerouteconfig.updateById();
        return R.trueOrFalse(b);
    }

    @SysLogger("删除路由参数配置")
    @PostMapping("/delete")
    public R delete(@RequestBody Integer configId) {
        DeviceRouteConfig route = routeConfigService.getById(configId);
        if (route != null) {
            return R.trueOrFalse(route.deleteById());
        }
        return R.ok();
    }
}
